package com.zznj.xzjc.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.SimpleItemAnimator;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.google.gson.Gson;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.vondear.rxtool.RxActivityTool;
import com.zznj.xzjc.R;
import com.zznj.xzjc.adapter.ZnyjAdapter;
import com.zznj.xzjc.adapter.index.CuiBanAdapter;
import com.zznj.xzjc.base.BaseActivity;
import com.zznj.xzjc.bean.index.CuiBanData;
import com.zznj.xzjc.bean.index.CuiBanResult;
import com.zznj.xzjc.event.EventTag;
import com.zznj.xzjc.event.MessageEvent;
import com.zznj.xzjc.net.SharedHelper;
import com.zznj.xzjc.net.entity.BaseBean;
import com.zznj.xzjc.net.entity.DiaoChaQuZhengBean;
import com.zznj.xzjc.net.entity.LcjdBean;
import com.zznj.xzjc.net.entity.LoginBean;
import com.zznj.xzjc.net.rxjava.HttpMethods;
import com.zznj.xzjc.net.subscribers.ProgressSubscriber;
import com.zznj.xzjc.net.subscribers.SubscriberOnNextListener;
import com.zznj.xzjc.utils.StringUtils;
import com.zznj.xzjc.view.MaxHeightRecyclerView;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.Unbinder;
import okhttp3.FormBody;

/**
 * 描述：线索发现
 */
public class ActivityZnyjCuiBanDetail extends BaseActivity {
    Unbinder unbinder;
    @BindView(R.id.caseName)
    TextView caseName;
    @BindView(R.id.yqTime)
    TextView yqTime;
    @BindView(R.id.rec_main)
    RecyclerView rec_main;

    @Override
    protected int getLayoutId() {
        return R.layout.gyss_activity_znyjcuiban_detail_layout;
    }

    private String caseId;
    private String proposalId;
    @Override
    public void initView() {
        caseId = getIntent().getExtras().getString("caseId");
        proposalId = getIntent().getExtras().getString("proposalId");
        setTitle("催办详情");
        init();
    }

    @Override
    protected void initData() {
        getData();
    }

    private List<CuiBanData> list;
    private CuiBanAdapter mAdapter;
    private void init() {
        list = new ArrayList<>();
        ((SimpleItemAnimator) rec_main.getItemAnimator()).setSupportsChangeAnimations(false);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        rec_main.setLayoutManager(linearLayoutManager);
        mAdapter = new CuiBanAdapter(R.layout.gyss_item_cuiban, list);
        rec_main.setAdapter(mAdapter);
    }

    private void getData() {
        SubscriberOnNextListener<BaseBean<CuiBanResult>> onNextListener = baseBean -> {
            list.addAll(baseBean.getResult().getPressSendList());
            mAdapter.notifyDataSetChanged();
            if(StringUtils.isEmpty(caseId)){
                caseName.setText(baseBean.getResult().getProposalSend().getTitle());
                yqTime.setText("逾期"+baseBean.getResult().getProposalSend().getTimeOutDay()+"天");
            }else{
                caseName.setText(baseBean.getResult().getCaseBasic().getCaseName());
                yqTime.setText("逾期"+baseBean.getResult().getCaseBasic().getWarnTime()+"天");
            }
        };
        if(StringUtils.isEmpty(caseId)){
            HttpMethods.getInstance().urgeProposalTips(new ProgressSubscriber<>(onNextListener, mContext, true), proposalId);
        }else{
            HttpMethods.getInstance().urgeTips(new ProgressSubscriber<>(onNextListener, mContext, true), caseId);
        }

    }
}
